public class 最长公共前缀 {
    public String longestCommonPrefix(String[] strs) {
        StringBuilder sb = new StringBuilder();
        int cnt = 0;
        boolean flag = true;
        while (flag) {
            char ch = strs[0].charAt(cnt);
            for (int i = 0; i < strs.length; i++) {
                if (cnt < strs[i].length() && ch != strs[i].charAt(cnt)) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                sb.append(ch);
            }
        }
        return sb.toString();
    }
}
